<!DOCTYPE html>
<HTML>

<HEAD>
    <TITLE> ZTREE DEMO </TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="/ztree/js/jquery-1.4.4.min.js"></script>
    <link rel="stylesheet" href="/ztree/css/demo.css" type="text/css">
    <link rel="stylesheet" href="/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/ztree/api/apiCss/jquery.ztree.core.js"></script>
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    <style>
        .ztree li span.button.icon01_ico_docu {
            background: url(js/zTree-zTree_v3-master/zTree_v3/css/zTreeStyle/img/index.png);
            margin-right: 2px;
            background-position: -110px -16px;
            vertical-align: top;
            no-repeat: scroll 0 0 transparent;
            vertical-align: top;
            *vertical-align: middle
        }

        .ztree li span.button.icon01_ico_open, .ztree li span.button.icon01_ico_close {
            background: url(js/zTree-zTree_v3-master/zTree_v3/css/zTreeStyle/img/index.png);
            margin-right: 2px;
            background-position: -110px -16px;
            vertical-align: top;
            no-repeat: scroll 0 0 transparent;
            vertical-align: top;
            *vertical-align: middle
        }
    </style>
</HEAD>

<BODY>
<div>
    <ul id="treeDemo" class="ztree"></ul>
</div>
</BODY>
<SCRIPT>

    var $ = layui.$;
    layui.config({
        base: 'viewstyle/' //主页样式的嵌入地址
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index']);
    var zTreeObj;
    var setting = {
        view: {
            dblClickExpand: false,
            showLine: true,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootPId: "0"
            }
        },
        callback: {
            onDblClick: itemDblClick,//双击事件
            onMouseDown: itemMouseDown //单击事件
        }
    };

    function itemDblClick(event, treeId, treeNode) {
        var adminid = treeNode ? treeNode.id : "isRoot";
        if (adminid != "isRoot") {
            var $ = layui.$
                , admin = layui.admin
                , element = layui.element
                , router = layui.router();
            var othis = $(this)
                , href = 'users/users.html'
                , text = '用户管理'
                , router = layui.router();
            admin.tabsPage.elem = othis;
            //执行跳转
            var topLayui = parent === self ? layui : top.layui;
            topLayui.index.openTabsPage(href, text || othis.text());
            layui.data("treeadminid", {
                key: "adminid",
                value: adminid
            })
        }
    }

    function itemMouseDown(event, treeId, treeNode) {
        var adminid = treeNode ? treeNode.id : "isRoot";
        if (adminid != "isRoot") {
            /*var $ = layui.$
                , admin = layui.admin
                , element = layui.element
                , router = layui.router();
            var othis = $(this)
                , href = 'station/EditStationByAdminid.html'
                , text = '站点管理'
                , router = layui.router();
            admin.tabsPage.elem = othis;
            //执行跳转
            var topLayui = parent === self ? layui : top.layui;
            topLayui.index.openTabsPage(href, text || othis.text());
            layui.data("treeadminid", {
                key: "adminid",
                value: adminid
            })*/
            layer.closeAll();
            layui.data("treeadminid", {
                key: "adminid",
                value: adminid
            })
            layer.open(
                {
                    title: '站点管理',
                    content: 'station/EditStationByAdminid.html',
                    type: 2,
                    area: ['100%', '100%'],
                    end: function () {
                        $(".layui-laypage-btn").click();
                    }
                }
            );
        }
    }

    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）m


</SCRIPT>


<script>
    //树型菜单的jquery和layui的jquery冲突解决
    var token = layui.data("local_store").token;

    $.ajax({
        type: "get",
        url: "/admin/selectShujsonById",
        data: {
            token: token
        },
        async: true,
        success: function (res) {
            $j = jQuery.noConflict();
            var treeNodes = eval(eval(res).data);
            zTreeObj = $j.fn.zTree.init($j("#treeDemo"), setting, treeNodes);
        }
    });
</script>


</HTML>